{% extends "base.html" %}

{% block title %}成绩统计分析{% endblock %}

{% block content %}
<div class="container">
    <div class="row mb-4">
        <div class="col-md-12">
            <h1 class="display-5">成绩统计分析</h1>
        </div>
    </div>
    
    <!-- 课程统计卡片 -->
    <div class="row mb-5">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header bg-info text-white">
                    <h3 class="card-title">课程成绩统计</h3>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-striped table-hover">
                            <thead>
                                <tr>
                                    <th>课程名称</th>
                                    <th>选课人数</th>
                                    <th>平均分</th>
                                    <th>最高分</th>
                                    <th>最低分</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for stat in course_stats %}
                                <tr>
                                    <td>{{ stat.name }}</td>
                                    <td>{{ stat.student_count or 0 }}</td>
                                    <td>
                                        {% if stat.avg_score is not none %}
                                        <span class="font-weight-bold">{{ "%.2f"|format(stat.avg_score) }}</span>
                                        {% else %}
                                        -
                                        {% endif %}
                                    </td>
                                    <td>{{ stat.max_score or '-' }}</td>
                                    <td>{{ stat.min_score or '-' }}</td>
                                    <td>
                                        <a href="{{ url_for('course_scores', id=loop.index) }}" class="btn btn-sm btn-primary">
                                            <i class="fas fa-list-alt me-1"></i>查看详情
                                        </a>
                                    </td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <!-- 学生统计卡片 -->
    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header bg-success text-white">
                    <h3 class="card-title">学生成绩统计</h3>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-striped table-hover">
                            <thead>
                                <tr>
                                    <th>学生姓名</th>
                                    <th>已修课程数</th>
                                    <th>平均分</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for stat in student_stats %}
                                <tr>
                                    <td>{{ stat.name }}</td>
                                    <td>{{ stat.course_count or 0 }}</td>
                                    <td>
                                        {% if stat.avg_score is not none %}
                                        <span class="font-weight-bold">{{ "%.2f"|format(stat.avg_score) }}</span>
                                        {% else %}
                                        -
                                        {% endif %}
                                    </td>
                                    <td>
                                        <a href="{{ url_for('student_scores', id=loop.index) }}" class="btn btn-sm btn-primary">
                                            <i class="fas fa-list-alt me-1"></i>查看详情
                                        </a>
                                    </td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}